package com.leetcode.algorithm.y22.m07;

import com.leetcode.algorithm.common.ListNode;

/**
 * 203. 移除链表元素
 * 
 * https://leetcode.cn/problems/remove-linked-list-elements/
 * 
 * @author jie.deng
 *
 */
class Question0203Solution02 {

	public ListNode removeElements(ListNode head, int val) {
		ListNode sentinel = new ListNode(-1);
		sentinel.next = head;
		ListNode prev = sentinel;
		while (prev.next != null) {
			if (prev.next.val == val) {
				prev.next = prev.next.next;
			} else {
				prev = prev.next;
			}
		}
		return sentinel.next;
	}

}